from django.urls import path
from .views import DeviceViewSet, DeviceTypeViewSet

# 按照 DRF ViewSet 的 as_view() 语法，把每个 HTTP 方法映射到具体方法
# 设备管理
device_list = DeviceViewSet.as_view({
    'get': 'list',
    'post': 'create',
})

device_detail = DeviceViewSet.as_view({
    'get': 'retrieve',
    'delete': 'destroy',
})

device_state = DeviceViewSet.as_view({
    'patch': 'update_state',
})

device_history = DeviceViewSet.as_view({
    'get': 'state_history',
})

# 设备类型管理
device_type_list = DeviceTypeViewSet.as_view({
    'get': 'list',
})

urlpatterns = [
    path('device-types', device_type_list, name='device-type-list'),
    # 列表 & 新增
    path('devices', device_list, name='device-list'),
    # 详情 & 删除
    path('devices/<int:pk>', device_detail, name='device-detail'),
    # 状态更新
    path('devices/<int:pk>/state', device_state, name='device-update-state'),
    # 状态历史
    path('devices/<int:pk>/state-history', device_history, name='device-state-history'),
]
